package com.rran.study.designpattern.behavioral.memento;

import lombok.Data;

import java.util.Random;

/**
 * @author yy
 * @Type Memento.java
 * @Desc 存档
 * @date 2020/7/24 12:30
 */
@Data
public class Memento {

    /**
     * 索引
     */
    private String index;

    /**
     * 第几关
     */
    private int gameLevel;

    /**
     * 血量
     */
    private Long blood;

    public Memento(){
        this.index = getRandomString(5);
    }


    public static String getRandomString(int length){
        String str="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        Random random=new Random();
        StringBuffer sb=new StringBuffer();
        for(int i=0;i<length;i++){
            int number=random.nextInt(62);
            sb.append(str.charAt(number));
        }
        return sb.toString();
    }

}
